package lesson04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class JButtonDemo01 extends JFrame {
    public  JButtonDemo01(){
        Container container=getContentPane();
        //将一个图片变为图标
        URL resource=JButtonDemo01.class.getResource("tx.jpg");
        Icon icon=new ImageIcon(resource);

        //把这个图标放在按钮上
        JButton jb=new JButton();
        jb.setIcon(icon);
        jb.setToolTipText("图片按钮");

        //容器add
        container.add(jb);
        setVisible(true);
        setBounds(200,200,400,400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
       new JButtonDemo01();
    }
}
